package com.kly.cashmall.module.products.adapter;

import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kly.cashmall.R;
import com.kly.cashmall.bean.RepaymentPlansBean;

/**
 * author :
 * date   : 2019-12-25 14:09
 * desc   :
 */
public class RepayPlanListAdapter extends BaseQuickAdapter<RepaymentPlansBean, BaseViewHolder> {

    public RepayPlanListAdapter() {
        super(R.layout.item_repayment_plan);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, RepaymentPlansBean repaymentPlansBean) {
        holder.setText(R.id.item_number,String.valueOf(holder.getAdapterPosition() + 1));
        String amount = repaymentPlansBean.getRepaymentAmount();
        SpannableString spannableString = new SpannableString(amount);
        if (amount.contains("₹")){
            spannableString.setSpan(new RelativeSizeSpan(0.78f), amount.indexOf("₹"), amount.indexOf("₹") + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        holder.setText(R.id.item_total_amount, spannableString);
        holder.setText(R.id.item_pricipal,"Principal: "+repaymentPlansBean.getPrincipal());
        holder.setText(R.id.item_interest,"interest: "+repaymentPlansBean.getInterest());
        holder.setText(R.id.item_repay_date,"Repay Date: "+repaymentPlansBean.getRepaymentDate());
        holder.setVisible(R.id.item_line, holder.getAdapterPosition() + 1 != getItemCount());
    }
}
